<script setup lang="jsx">
import { computed, reactive, ref } from 'vue';
import { useElementSize } from '@vueuse/core';
import { DeleteOutlined, DownloadOutlined, EditOutlined, PlusOutlined, SearchOutlined } from '@ant-design/icons-vue';
import useResetTableRef from '@/hooks/common/resetTableRef';
import useSearchData from '@/hooks/common/searchData';
import { vcpget, vcppost } from '@/service/api/modules/erp';
const [searchParams, resetSearchParams] = useResetTableRef({
  prodNo: null,
  time: null
});
const tableRef = ref(null);
const tableRefs = ref(null);
const tableRefs1 = ref(null);
const searchData = useSearchData(searchParams);
const tableDatas = ref([]);
const searchFormList = [
  {
    type: 'input',
    key: 'prodNo',
    label: '生产型号',
    span: 24,
    md: 12,
    lg: 10,
    xl: 4,
    xxl: 4,
    placeholder: '请输入生产型号',
    showTime: true
  },
  {
    type: 'dateRangePicker',
    key: 'time',
    label: '日期',
    span: 24,
    md: 12,
    lg: 10,
    xl: 8,
    xxl: 6,
    showTime: true // 显示时分秒选择
  }
];
const searchFormList2 = [
  {
    type: 'input',
    key: 'prodOrderNo',
    label: '工单号码',
    span: 24,
    md: 12,
    lg: 10,
    xl: 6,
    xxl: 6,
    placeholder: '请输入工单号码',
    showTime: true
  },
  {
    type: 'input',
    key: 'prodNo',
    label: '生产型号',
    span: 24,
    md: 12,
    lg: 10,
    xl: 6,
    xxl: 6,
    placeholder: '请输入生产型号',
    showTime: true
  }
];
const searchFormList3 = [
  {
    type: 'input',
    key: 'lotNo',
    label: '批卡号',
    span: 24,
    md: 12,
    lg: 10,
    xl: 6,
    xxl: 6,
    placeholder: '请输入批卡号',
    showTime: true
  },
  {
    type: 'input',
    key: 'prodNo',
    label: '生产型号',
    span: 24,
    md: 12,
    lg: 10,
    xl: 6,
    xxl: 6,
    placeholder: '请输入生产型号',
    showTime: true
  }
];
const pagination = reactive({
  current: 1,
  pageSize: 200,
  showSizeChanger: true,
  pageSizeOptions: ['50', '100', '200', '300', '500'],
  showQuickJumper: true,
  showTotal: total => {
    return `共${total}条`;
  },
  total: 0,
  onChange: async (current, size) => {
    pagination.current = current;
    pagination.pageSize = size;
    getData();
  }
});
const zzgxSlecet = ref([]);
// const zzbmSlecet = ref([]);

const ccyySlecet = ref([]);
const columns = ref([
  {
    key: 'dataIndex',
    dataIndex: 'dataIndex',
    title: '序号',
    width: 100,
    align: 'center',
    checked: true
  },
  {
    key: 'state',
    dataIndex: 'state',
    title: '状态',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true,
    customRender: record => {
      return <div style={{ color: getTextColor1(record.record.state) }}>{getTextColor(record.record.state)}</div>;
    }
  },
  {
    key: 'pmeState',
    dataIndex: 'pmeState',
    title: '工艺状态',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true,
    customRender: record => {
      return <div style={{ color: getTextColor1(record.record.pmeState) }}>{getTextColor(record.record.pmeState)}</div>;
    }
  },
  {
    key: 'applyNo',
    dataIndex: 'applyNo',
    title: '申请单号',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'techName',
    dataIndex: 'techName',
    title: '申请工艺',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'prodNo',
    dataIndex: 'prodNo',
    title: '产品型号',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'custProdNo',
    dataIndex: 'custProdNo',
    title: '客户型号',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'prodType',
    dataIndex: 'prodType',
    title: '产品类型',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'unit',
    dataIndex: 'unit',
    title: '单位',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'qty',
    dataIndex: 'qty',
    title: '数量',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'scrapSet',
    dataIndex: 'scrapSet',
    title: '含废SET',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'scrapPcs',
    dataIndex: 'scrapPcs',
    title: '含废PCS',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'caption',
    dataIndex: 'caption',
    title: '重工原因',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'repDeptCaptoin',
    dataIndex: 'repDeptCaptoin',
    title: '责任部门',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'remark',
    dataIndex: 'remark',
    title: '备注',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'createBy',
    dataIndex: 'createBy',
    title: '申请人',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'createDate',
    dataIndex: 'createDate',
    title: '申请日期',
    sorter: true,
    width: 160,
    align: 'center',
    checked: true,
    ellipsis: true
  }
]);
const columns1 = ref([
  {
    key: 'dataIndex',
    dataIndex: 'dataIndex',
    title: '序号',
    width: 100,
    align: 'center',
    checked: true
  },
  {
    key: 'lotNo',
    dataIndex: 'lotNo',
    title: '批卡号',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'qty',
    dataIndex: 'qty',
    title: '数量',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'unit',
    dataIndex: 'unit',
    title: '单位',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'custDateCode',
    dataIndex: 'custDateCode',
    title: '周期数量',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'scrapSet',
    dataIndex: 'scrapSet',
    title: '废set数量',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'scrapPcs',
    dataIndex: 'scrapPcs',
    title: '废pcs数量',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'createBy',
    dataIndex: 'createBy',
    title: '创建者',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'createDate',
    dataIndex: 'createDate',
    title: '创建时间',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  }
]);
const columns2 = ref([
  {
    key: 'dataIndex',
    dataIndex: 'dataIndex',
    title: '序号',
    width: 100,
    align: 'center',
    checked: true
  },
  {
    key: 'batchNo',
    dataIndex: 'batchNo',
    title: '批卡号',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },

  {
    key: 'mantissaPercent',
    dataIndex: 'mantissaPercent',
    title: '单位',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'prodNo',
    dataIndex: 'prodNo',
    title: '周期数量',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'prodNo',
    dataIndex: 'prodNo',
    title: '数量',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'custProdNo',
    dataIndex: 'custProdNo',
    title: '废Set数量',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'custProdNoAdd',
    dataIndex: 'custProdNoAdd',
    title: '废Pcs数量',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  }
]);
const columns3 = ref([
  {
    key: 'index',
    dataIndex: 'index',
    title: '序号',
    width: 80,
    align: 'center',
    checked: true
  },
  {
    key: 'prodOrderNo',
    dataIndex: 'prodOrderNo',
    title: '工单号码',
    sorter: true,
    align: 'center',
    width: 200,
    checked: true
  },

  {
    key: 'prodNo',
    dataIndex: 'prodNo',
    title: '生产型号',
    sorter: true,
    align: 'center',
    checked: true,
    width: 100
  },
  {
    key: 'custProdNo',
    dataIndex: 'custProdNo',
    title: '客户型号',
    sorter: true,
    align: 'center',
    checked: true,
    width: 300,
    ellipsis: true
  },
  {
    key: 'pnlQty',
    dataIndex: 'pnlQty',
    title: 'Pnl数量',
    sorter: true,
    align: 'center',
    checked: true,
    width: 100
  },
  {
    key: 'pcsQty',
    dataIndex: 'pcsQty',
    title: 'Pcs数量',
    sorter: true,
    align: 'center',
    checked: true,
    width: 110
  },
  {
    key: 'pnlSet',
    dataIndex: 'pnlSet',
    title: '1Pnl=?Set',
    sorter: true,
    align: 'center',
    checked: true,
    width: 110
  },
  {
    key: 'setPcs',
    dataIndex: 'setPcs',
    title: '1Set=?Pcs',
    sorter: true,
    align: 'center',
    checked: true,
    width: 110
  },
  // {
  //   key: 'custProdNoAdd',
  //   dataIndex: 'custProdNoAdd',
  //   title: '结存面积',
  //   sorter: true,
  //   align: 'center',
  //   checked: true,
  //   width: 100
  // },
  {
    key: 'surfTrea2',
    dataIndex: 'surfTrea2',
    title: '有效单元',
    sorter: true,
    align: 'center',
    checked: true,
    width: 100
  }
]);
const columns4 = ref([
  {
    key: 'index',
    dataIndex: 'index',
    title: '序号',
    width: 80,
    align: 'center',
    checked: true
  },
  {
    key: 'lotNo',
    dataIndex: 'lotNo',
    title: '批卡号',
    sorter: true,
    align: 'center',
    width: 160,
    checked: true
  },

  {
    key: 'prodNo',
    dataIndex: 'prodNo',
    title: '生产型号',
    sorter: true,
    align: 'center',
    checked: true,
    width: 100
  },
  {
    key: 'custProdNo',
    dataIndex: 'custProdNo',
    title: '客户型号',
    sorter: true,
    align: 'center',
    checked: true,
    width: 120,
    ellipsis: true
  },
  {
    key: 'wipUnit',
    dataIndex: 'wipUnit',
    title: '单位',
    sorter: true,
    align: 'center',
    checked: true,
    width: 100
  },
  {
    key: 'wipQty',
    dataIndex: 'wipQty',
    title: '数量',
    sorter: true,
    align: 'center',
    checked: true,
    width: 110,
    customRender: record => {
      return (
        <div>
          <a-input-number
            v-model:value={record.record.wipQty}
            onChange={e => {
              console.log(e, record);
              record.record.wipQty = e;
            }}
          ></a-input-number>
        </div>
      );
    }
  },
  {
    key: 'wipScrapSet',
    dataIndex: 'wipScrapSet',
    title: '废SET数',
    sorter: true,
    align: 'center',
    checked: true,
    width: 110
  },
  {
    key: 'wipScrapPcs',
    dataIndex: 'wipScrapPcs',
    title: '废PCS数',
    sorter: true,
    align: 'center',
    checked: true,
    width: 110
  },

  {
    key: 'workState',
    dataIndex: 'workState',
    title: '生产状态',
    sorter: true,
    align: 'center',
    checked: true,
    width: 100
  },
  {
    key: 'wipState',
    dataIndex: 'wipState',
    title: '结存状态',
    sorter: true,
    align: 'center',
    checked: true,
    width: 100
  },

  {
    key: 'createDate',
    dataIndex: 'createDate',
    title: '入账时间',
    sorter: true,
    align: 'center',
    checked: true,
    width: 160
  },

  {
    key: 'finishDate',
    dataIndex: 'finishDate',
    title: '完成时间',
    sorter: true,
    align: 'center',
    checked: true,
    width: 100
  },

  {
    key: 'createBy',
    dataIndex: 'createBy',
    title: '入账员',
    sorter: true,
    align: 'center',
    checked: true,
    width: 100
  }
]);
const zzbmSlecet = [
  {
    label: '部门1',
    value: '1',
    children: [
      {
        label: '子部门1-1',
        value: '1-1'
      }
    ]
  },
  {
    label: '部门2',
    value: '2'
  }
];
const formList = [
  {
    type: 'input',
    key: 'applyNo',
    label: '申请单号',
    disabled: true,
    span: 8
  },
  {
    type: 'select',
    key: 'techId',
    showSearch: true,
    label: '制造工艺',
    selectOptions: zzgxSlecet,
    placeholder: '请选择制造工艺产',
    span: 8
  },
  {
    type: 'input',
    key: 'prodNo',
    label: '生产型号',
    placeholder: '请选择生产型号',
    suffixSlot: <SearchOutlined class="cursor-pointer" onClick={() => handleSearch()} />,
    span: 8
  },
  {
    type: 'select',
    key: 'causeId',
    selectOptions: ccyySlecet,
    label: '重工原因',
    placeholder: '请选择重工原因',
    span: 8
  },
  {
    type: 'select',
    key: 'repDeptId',
    selectOptions: zzbmSlecet,
    label: '责任部门',
    placeholder: '请选择责任部门',
    span: 8
  },
  {
    type: 'input',
    key: 'prodOrderNo',
    label: '工单号码',
    placeholder: '请输入工单号码',
    disabled: true,
    span: 8
  },
  {
    type: 'input',
    key: 'remark',
    label: '备注',
    placeholder: '请填写备注',
    span: 8
  }
];
const selectedRowKeys = ref([]);
const detailsVisible = ref(false);
const searchParams1 = ref({
  pageNum: 1,
  pageSize: 200,
  applyId: ''
});
const searchParams2 = ref({
  pageNum: 1,
  pageSize: 200,
  techId: ''
});
const searchParams3 = ref({
  pageNum: 1,
  pageSize: 200,
  techId: '',
  prodId: '',
  processId: ''
});
const upDatas = ref({});
const addDatas = ref({});
const titles = ref('');
const detailsVisibleBotton = ref(false);
const detailsVisibleZyd = ref(false);
const tableDataBotton = ref([]);
function updata() {
  if (selectedRowKeys.value.length != 1) {
    return window.$message?.error('请先选择一条数据');
  }
  getZzgyList();
  getZzbmList();
  titles.value = '重工申请修改';
  upDatas.value = tableRef.value.tableData.find(person => selectedRowKeys.value[0].prodId == person.prodId);

  searchParams3.value.prodId = upDatas.value.prodId;
  searchParams3.value.processId = upDatas.value.processId;
  searchParams3.value.techId = upDatas.value.techId;
  vcpget('/jlerp/rework/findPpcWip', searchParams3.value).then(({ data, error }) => {
    if (!error) {
      data.list.forEach((item, index) => {
        item.index = index + 1;
      });
      tableDataBotton.value = data.list;
    }
  });

  detailsVisible.value = true;
}
function addData() {
  titles.value = '重工申请新增';
  addDatas.value = {};
  getZzgyList();
  // getZzbmList();
  detailsVisible.value = true;
}

function addDataBotton() {
  // detailsVisibleBotton.value = true;
  if (titles.value == '重工申请新增') {
    searchParams3.value.prodId = addDatas.value.prodId;
    searchParams3.value.processId = addDatas.value.processId;
    searchParams3.value.techId = addDatas.value.techId;
    vcpget('/jlerp/rework/findPpcWip', searchParams3.value).then(({ data, error }) => {
      if (!error) {
        data.list.forEach((item, index) => {
          item.index = index + 1;
        });
        tableDataBotton.value = data.list;
      }
    });
  } else {
    searchParams3.value.prodId = upDatas.value.prodId;
    searchParams3.value.processId = upDatas.value.processId;
    searchParams3.value.techId = upDatas.value.techId;
    vcpget('/jlerp/rework/findPpcWip', searchParams3.value).then(({ data, error }) => {
      if (!error) {
        data.list.forEach((item, index) => {
          item.index = index + 1;
        });
        tableDataBotton.value = data.list;
      }
    });
  }
}
const tableData = ref([]);
function handleSearch() {
  if (titles.value == '重工申请新增') {
    if (!addDatas.value.techId) {
      return window.$message?.error('请先选择工艺');
    }
    searchParams2.value.techId = addDatas.value.techId;
    vcpget('/jlerp/rework/findTechPpcWip', searchParams2.value).then(({ data, error }) => {
      if (!error) {
        data.list.forEach((item, index) => {
          item.index = index + 1;
        });
        tableData.value = data.list;
      }
    });
  } else {
    searchParams2.value.techId = upDatas.value.techId;
    searchParams2.value.prodId = upDatas.value.prodId;
    searchParams2.value.processId = upDatas.value.processId;
    console.log(searchParams2.value, 21546);

    vcpget('/jlerp/rework/findTechPpcWip', searchParams2.value).then(({ data, error }) => {
      if (!error) {
        data.list.forEach((item, index) => {
          item.index = index + 1;
          tableData.value = data.list;
        });
      }
    });
  }
  detailsVisibleZyd.value = true;
}
const reworkApplyDetailList = ref([]);
function getUpdata() {
  upDatas.value.reworkApplyDetailList = reworkApplyDetailList.value;
  vcppost('/jlerp/rework/updateRework', upDatas.value).then(({ data, error }) => {
    if (!error) {
      detailsVisible.value = false;
      upDatas.value = '';
      window.$message?.success('修改成功');
      selectedRowKeys.value = [];
      tableRef.value.getData(1);
    }
  });
}
function getZzgyList() {
  vcpget('/jlerp/rework/findDeptLinkTech', '').then(({ data, error }) => {
    if (!error) {
      zzgxSlecet.value = data.map(item => ({
        label: item.techName,
        value: item.techID
      }));
    }
  });
}
function openDetailsVisible() {
  detailsVisible.value = false;
  tableDataBotton.value = [];
}
// function getZzbmList() {
//   vcpget('/jlerp/rework/findDepartment', '').then(({ data, error }) => {
//     if (!error) {
//       zzbmSlecet.value = data.map(item => ({
//         label: item.deptCaption,
//         value: item.deptId,
//      children: item.children ? item.children.map(child => ({
// title: child.label,
//       key: child.value,
//     })) : undefined,
//       }));
//     }
//   });
// }
function getCgyyList(val) {
  const obj = {
    prodId: val
  };
  vcpget('/jlerp/rework/findReasonProRework', obj).then(({ data, error }) => {
    if (!error) {
      ccyySlecet.value = data.map(item => ({
        label: item.caption,
        value: item.reasonId
      }));
    }
  });
}
function getTextColor(v) {
  switch (Number(v)) {
    case -1:
      return '无ICS';
    case 0:
      return '新录入';
    case 1:
      return '更改';
    case 2:
      return '待处理';
    case 3:
      return '处理中';
    case 4:
      return '暂停';
    case 5:
      return '拒审';
    case 6:
      return '反审核';
    case 7:
      return '审核中';
    case 8:
      return '生效';
    case 9:
      return '完成';
    case 10:
      return '取消';
    case 11:
      return '外部ECN';
    case 12:
      return '外部ECN处理中';
    case 13:
      return '内部ECN处';
    case 19:
      return '样板转生产';
    case 21:
      return '改变';
    case 22:
      return '待投料';
    case 23:
      return '已投料';
    case 25:
      return '失效';
    case 999:
      return '系统完成';
    default: {
      if (v == 1503311132310000) return '初审';
      idx = me.store.find('audId', v);
      if (idx >= 0) return me.store.getAt(idx).get('audName');
      return 'Error:"audId" not found';
    }
  }
}
function getTextColor1(v) {
  switch (Number(v)) {
    case 0:
      return '#0080FF';
    case 1:
      return '#E1E100';
    case 2:
      return '#FF8000';
    case 3:
      return '#B15BFF';
    case 4:
      return '#73BF00';
    case 5:
      return '#8E8E8E';
    case 6:
      return '#BEBEBE';
    case 7:
      return '#FF0000';
    case 8:
      return '#BEBEBE';
    case 9:
      return '#0000FF';
    case 10:
      return '#007500';
    case 21:
      return '#FF4500';
    case 25:
      return '#00CED1';
    default:
      return '#0000FF';
  }
}

function handleSelectChanges(val) {
  reworkApplyDetailList.value = val;
}
function getAddData() {
  addDatas.value.reworkApplyDetailList = reworkApplyDetailList.value;
  vcppost('/jlerp/rework/saveRework', addDatas.value).then(({ data, error }) => {
    if (!error) {
      detailsVisible.value = false;
      addDatas.value = {};
      window.$message?.success('新增成功');
      selectedRowKeys.value = [];
      // getData();
      tableRef.value.getData(1);
    }
  });
}
function deleteDataTbe() {
  if (selectedRowKeys.value.length == 0) {
    return window.$message?.error('请先选择至少一条数据');
  }
  const arr = [];
  arr.push(selectedRowKeys.value[0].applyId);
  window.$modal?.confirm({
    title: `是否确认删除数据?`,
    onOk: () => {
      vcppost('/jlerp/rework/deleteRework', arr).then(({ data, error }) => {
        if (!error) {
          detailsVisible.value = false;
          addDatas.value = {};
          window.$message?.success('删除成功');
          selectedRowKeys.value = [];
          // getData();
          tableRef.value.getData(1);
        }
      });
    },
    onCancel: () => {}
  });
}
function deleteData() {
  if (reworkApplyDetailList.value.length == 0) {
    return window.$message?.error('请先选择至少一条数据');
  }

  window.$modal?.confirm({
    title: `是否确认删除数据?`,
    onOk: () => {
      const selectData = [];
      tableDataBotton.value.forEach(el => {
        if (reworkApplyDetailList.value.some(item => item.fullProdNo !== el.fullProdNo)) {
          selectData.push(el);
        }
      });
      selectData.forEach((item, index) => {
        item.index = index + 1;
      });
      tableDataBotton.value = selectData;
    },
    onCancel: () => {}
  });
}
function deleteDatas() {
  window.$modal?.confirm({
    title: `是否确认删除所有数据?`,
    onOk: () => {
      tableDataBotton.value = [];
      reworkApplyDetailList.value = [];
    },
    onCancel: () => {}
  });
}
function search() {
  tableRef.value.getData(1);
}
function search3() {
  addDataBotton();
}
function search2() {
  handleSearch();
}

function reset() {
  resetSearchParams();
  search();
}

function handleSelectChange(val) {
  selectedRowKeys.value = val;
  console.log(val[0].applyId);

  if (val[0].applyId) {
    searchParams1.value.applyId = val[0].applyId;
    tableRefs.value.getData();
  }
}
function tableRowClick(val) {
  searchParams1.value.applyId = val.applyId;
  // getBootom();
  tableRefs.value.getData();
}

function tableRowClicks(val) {
  // searchParams1.value.applyId = val.applyId;
  upDatas.value = val;
  addDatas.value = val;
  // upDatas.value.prodId = val.prodId;
  // addDatas.value.prodId = val.prodId;
  // upDatas.value.processId = val.processId;
  // addDatas.value.processId = val.processId;
  // addDatas.value.prodNo = val.prodNo;
  // upDatas.value.prodNo = val.prodNo;
  // addDatas.value.prodOrderNo = val.prodOrderNo;
  // upDatas.value.prodOrderNo = val.prodOrderNo;
  getCgyyList(val.prodId);

  // tableDataBotton.value.push(val);
  // tableDataBotton.value = [...tableDataBotton.value];
  addDataBotton();
  console.log(addDatas.value, upDatas.value);

  // getBootom();
  // tableRefs.value.getData();
}
function tableRowClicksB(val) {}
function getBootom() {
  vcpget('/rcerp/orderInfo/findDetailCustOrder', searchParams1.value).then(({ data, error }) => {
    if (!error) {
      tableDatas.value = data.list;
    }
  });
}

function handleDataLoadSucess(data) {
  const selectData = ref([]);
  data.forEach(el => {
    if (tableRefs.value.tableData.some(item => item.lotNo == el.lotNo)) {
      selectData.value.push(el);
    }
  });
  console.log(selectData.value);
  console.log(data);

  if (titles.value == '重工申请修改') {
    tableRefs1.value.setSelectRows(selectData.value);
  }
}
</script>

<template>
  <div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
    <!-- <Search v-model:model="searchParams" @reset="search()" @search="search()" /> -->
    <CommonSearch
      v-model:searchParams="searchParams"
      :form-list="searchFormList"
      @search="search"
      @reset="reset"
    ></CommonSearch>

    <Table
      ref="tableRef"
      v-model:searchParams="searchData"
      :column="columns"
      :show-row-selection="true"
      :auto-generate-uuid="true"
      :scroll="{ y: 'auto' }"
      is-init-get-data
      url="/jlerp//rework/findProRework"
      row-selection-type="radio"
      @table-select-change="handleSelectChange"
      @table-row-click="tableRowClick"
    >
      <template #title>
        <AButton type="primary" size="small" ghost class="mini-btn mr-8px" @click="addData">
          <template #icon>
            <PlusOutlined class="align-sub" />
          </template>
          新增
        </AButton>
        <AButton type="primary" size="small" ghost class="mini-btn mr-8px" @click="updata">
          <template #icon>
            <EditOutlined class="align-sub" />
          </template>
          修改
        </AButton>
        <AButton type="primary" size="small" ghost class="mini-btn mr-8px" @click="deleteDataTbe">
          <template #icon>
            <DeleteOutlined class="align-sub" />
          </template>
          删除
        </AButton>
        <!--
 <AButton type="primary" size="small" ghost class="mini-btn mr-8px" @click="deleteData">
          <template #icon>
            <DeleteOutlined class="align-sub" />
          </template>
          审核
        </AButton>
-->
      </template>
    </Table>

    <Table
      ref="tableRefs"
      v-model:searchParams="searchParams1"
      :column="columns1"
      :show-row-selection="false"
      :auto-generate-uuid="false"
      row-key="subApplyId"
      :scroll="{ y: 'auto' }"
      url="/jlerp//rework/findDetailProRework"
      :is-init-get-data="false"
      :summary-fixed="true"
    >
      <template #summary>
        <STableSummaryRow>
          <STableSummaryCell :index="0" :col-span="2" class="text-center">
            <div>
              <span style="font-size: 22px; font-weight: 600">合计:{{ tableRefs.tableData.length }}张批卡</span>
            </div>
          </STableSummaryCell>
          <STableSummaryCell :index="2" class="text-center">
            <template #default="{ total }">
              <span style="font-size: 16px; font-weight: 400">{{ total }}</span>
            </template>
          </STableSummaryCell>
          <STableSummaryCell :index="5" class="text-center">
            <template #default="{ total }">
              <span style="font-size: 16px; font-weight: 400">{{ total }}</span>
            </template>
          </STableSummaryCell>
          <STableSummaryCell :index="6" class="text-center">
            <template #default="{ total }">
              <span style="font-size: 16px; font-weight: 400">{{ total }}</span>
            </template>
          </STableSummaryCell>
        </STableSummaryRow>
      </template>
      <!-- suborderID -->

      <template #title>
        <div>
          <span>申请明细</span>
        </div>
      </template>
    </Table>

    <Modal
      v-model:visible="detailsVisible"
      :destroy-on-close="true"
      :centered="true"
      :title="titles"
      width="1050px"
      height="650px"
    >
      <div v-if="titles == '重工申请修改'" class="event-form">
        <Form v-model:model="upDatas" :form-list="formList"></Form>
      </div>
      <div v-else class="event-form">
        <Form v-model:model="addDatas" :form-list="formList"></Form>
      </div>

      <Table
        ref="tableRefs1"
        v-model:searchParams="searchParams3"
        class="h-100"
        :column="columns4"
        :show-row-selection="true"
        :show-card-header="true"
        :auto-generate-uuid="false"
        row-key="wipId"
        :scroll="{ y: 'auto' }"
        :data-source="tableDataBotton"
        :is-init-get-data="false"
        :summary-fixed="true"
        @table-data-load-sucess="handleDataLoadSucess"
        @table-select-change="handleSelectChanges"
      >
        <template #summary>
          <STableSummaryRow>
            <STableSummaryCell :index="1" :col-span="2" class="text-center">
              <div>
                <span style="font-size: 22px; font-weight: 600">合计:{{ tableDataBotton.length }}张批卡</span>
              </div>
            </STableSummaryCell>
            <STableSummaryCell :index="6" class="text-center">
              <template #default="{ total }">
                <span style="font-size: 16px; font-weight: 400">{{ total }}</span>
              </template>
            </STableSummaryCell>
            <STableSummaryCell :index="7" class="text-center">
              <template #default="{ total }">
                <span style="font-size: 16px; font-weight: 400">{{ total }}</span>
              </template>
            </STableSummaryCell>
            <STableSummaryCell :index="8" class="text-center">
              <template #default="{ total }">
                <span style="font-size: 16px; font-weight: 400">{{ total }}</span>
              </template>
            </STableSummaryCell>
          </STableSummaryRow>
        </template>
        <template #title>
          <div class="mr-8px">
            <span>申请明细</span>
          </div>
          <!--
 <AButton type="primary" size="small" ghost class="mini-btn mr-8px" @click="addDataBotton">
            <template #icon>
              <PlusOutlined class="align-sub" />
            </template>
            添加
          </AButton>
-->
          <AButton type="primary" size="small" ghost class="mini-btn mr-8px" @click="deleteData">
            <template #icon>
              <EditOutlined class="align-sub" />
            </template>
            删除
          </AButton>
          <AButton type="primary" size="small" ghost class="mini-btn mr-8px" @click="deleteDatas">
            <template #icon>
              <DeleteOutlined class="align-sub" />
            </template>
            删除全部
          </AButton>
        </template>
      </Table>

      <template #footer>
        <div class="modal-footer">
          <AButton @click="openDetailsVisible">关闭</AButton>
          <AButton v-if="titles == '重工申请修改'" @click="getUpdata">保存</AButton>
          <AButton v-else @click="getAddData">保存</AButton>
        </div>
      </template>
    </Modal>
    <div>
      <Modal
        v-model:visible="detailsVisibleZyd"
        :destroy-on-close="true"
        :mask="true"
        :centered="false"
        title="请选择重工型号"
        width="900px"
        height="600px"
      >
        <CommonSearch v-model:searchParams="searchParams" :form-list="searchFormList2" @search="search2"></CommonSearch>
        <Table
          ref="tableRefs2"
          v-model:searchParams="searchParams2"
          :column="columns3"
          :show-row-selection="true"
          :show-card-header="false"
          :auto-generate-uuid="false"
          class="h-100"
          row-key="index"
          :scroll="{ y: 'auto' }"
          :data-source="tableData"
          :is-init-get-data="false"
          @table-row-click="tableRowClicks"
        ></Table>

        <template #footer>
          <div class="modal-footer">
            <div>
              <AButton @click="detailsVisibleZyd = false">关闭</AButton>

              <AButton @click="getLogin">确定</AButton>
            </div>
          </div>
        </template>
      </Modal>
    </div>
    <div>
      <Modal
        v-model:visible="detailsVisibleBotton"
        :destroy-on-close="true"
        :mask="true"
        :centered="false"
        title="请选择申请批卡"
        width="900px"
        height="600px"
      >
        <CommonSearch v-model:searchParams="searchParams" :form-list="searchFormList3" @search="search3"></CommonSearch>
        <Table
          ref="tableRefs1"
          v-model:searchParams="searchParams3"
          :column="columns4"
          :show-row-selection="false"
          :show-card-header="false"
          :auto-generate-uuid="false"
          row-key="index"
          :scroll="{ y: 'auto' }"
          :data-source="tableDataBotton"
          :is-init-get-data="false"
          @table-row-click="tableRowClicksB"
        ></Table>

        <template #footer>
          <div class="modal-footer">
            <div>
              <AButton @click="detailsVisibleBotton = false">关闭</AButton>

              <AButton @click="detailsVisibleBotton = false">确定</AButton>
            </div>
          </div>
        </template>
      </Modal>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.row-red-background {
  background-color: rgba(244, 56, 56, 0.7) !important; /* !important 可能需要以确保覆盖其他样式 */
}
.expired {
  color: red;
  font-weight: bold;
  font-size: larger;
}

:deep(.surely-table-wrapper) {
  &.has-footer-table {
    .ant-spin-nested-loading {
      .ant-spin-container {
        .surely-table {
          height: calc(100% - 40px - v-bind('footerHeight')) !important;
        }
      }
    }
  }
}
</style>
